package cn.kone;

import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.PutObjectArgs;

import java.io.File;
import java.io.FileInputStream;

public class test {

    public static void main(String[] args) throws Exception {

        // 构建一个Minio客户端
        MinioClient minioClient = MinioClient.builder()
                //创建容器时指定的账号
                .credentials("minioadmin", "minioadmin123?")
                //上传地址
                .endpoint("http://101.35.235.40:9090").build();

        File file = new File("G:\\图片\\月球.jpeg");

        PutObjectArgs putObjectArgs = PutObjectArgs.builder()
                .object("kone_yueqiu.jpeg")	//文件名
                .contentType("image/jpeg")	//文件类型
                .bucket("wh-java1031")  //存储目录名
                .stream(new FileInputStream(file), file.length(), -1).build(); //文件流，以及大小，-1代表不分片

        //执行上传
        ObjectWriteResponse objectWriteResponse = minioClient.putObject(putObjectArgs);
        System.out.println("上传结果 "+objectWriteResponse);
    }

}
